﻿<Window x:Class="ULSDeobfuscator.ManageColorRulesWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:ULSDeobfuscator="clr-namespace:ULSDeobfuscator"
        xmlns:DropDownCustomColorPicker="clr-namespace:DropDownCustomColorPicker" mc:Ignorable="d" 
        d:DataContext="{d:DesignInstance Type=ULSDeobfuscator:ManageColorRulesViewModel}"
        Title="Manage Color Rules" 
        d:DesignHeight="400" d:DesignWidth="900"
        Left="{Binding WindowLeft, Mode=TwoWay}"
        Top="{Binding WindowTop, Mode=TwoWay}" 
        ShowInTaskbar="False">
    
    <Window.Resources>
        
    </Window.Resources>
    <Grid Margin="5">
        
        <Grid.RowDefinitions>
            <!-- 0: explanations -->
            <RowDefinition Height="Auto" />
            <!-- 1: rules list -->
            <RowDefinition Height="*" />
            <!-- 2: add button -->
            <RowDefinition Height="Auto" />
            <!-- 3: Default colors -->
            <RowDefinition Height="Auto" />
            <!-- 4: sample text -->
            <RowDefinition Height="Auto" />
            <!-- 5: OK/Cancel-->
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="*" />
            <ColumnDefinition Width="Auto" />
        </Grid.ColumnDefinitions>
        
        <StackPanel Grid.Row="0" Grid.ColumnSpan="2"
                    Margin="5">
            
            <TextBlock TextWrapping="Wrap" >
                Define the rules that set the colors of log entries.
            </TextBlock>
            <TextBlock TextWrapping="Wrap" 
                       Margin="0,10,0,0">
                Rules are evaluated in this order; the first rule to match wins.
            </TextBlock>
        </StackPanel>
        
        <ListView Grid.Row="1" Grid.Column="0"
                  ItemsSource="{Binding Rules, Mode=OneWay}"
                  SelectedItem="{Binding CurrentRule, Mode=TwoWay}"
                  SelectedIndex="{Binding CurrentRuleIndex, Mode=TwoWay}"
                  Margin="0,5,5,0"
                  SelectionMode="Single">
            <ListView.View>
                <GridView AllowsColumnReorder="False">
                    <GridView.Columns>

                        <GridViewColumn Header="Name" 
                                        Width="{Binding NameColumnWidth, Mode=TwoWay}"
                                        DisplayMemberBinding="{Binding Rule.Name}" />
                        <GridViewColumn Header="Color"
                                        Width="{Binding ColorColumnWidth, Mode=TwoWay}">
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <TextBlock Text="Brown fox" 
                                               HorizontalAlignment="Center">
                                        <TextBlock.Foreground>
                                            <SolidColorBrush Color="{Binding ForegroundColor}" />
                                        </TextBlock.Foreground>
                                        <TextBlock.Background>
                                            <SolidColorBrush Color="{Binding BackgroundColor}" />
                                        </TextBlock.Background>
                                    </TextBlock>
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Header="Process" 
                                        Width="{Binding ProcessColumnWidth, Mode=TwoWay}"
                                        DisplayMemberBinding="{Binding ProcessSummary}" />
                        <GridViewColumn Header="Area"
                                        Width="{Binding AreaColumnWidth, Mode=TwoWay}"
                                        DisplayMemberBinding="{Binding AreaSummary}" />
                        <GridViewColumn Header="Category"
                                        Width="{Binding CategoryColumnWidth, Mode=TwoWay}"
                                        DisplayMemberBinding="{Binding CategorySummary}" />
                        <GridViewColumn Header="Level"
                                        Width="{Binding LevelColumnWidth, Mode=TwoWay}"
                                        DisplayMemberBinding="{Binding LevelSummary}" />
                        <GridViewColumn Header="Event ID"
                                        Width="{Binding EventColumnWidth, Mode=TwoWay}"
                                        DisplayMemberBinding="{Binding EventIDSummary}" />
                        <GridViewColumn Header="Message"
                                        Width="{Binding MessageColumnWidth, Mode=TwoWay}"
                                        DisplayMemberBinding="{Binding Rule.Message}" />
                        <GridViewColumn Header="Correlation ID"
                                        Width="{Binding CorrelationColumnWidth, Mode=TwoWay}"
                                        DisplayMemberBinding="{Binding Rule.Correlation}" />
                        <GridViewColumn Header="Multi-line ?"
                                        Width="{Binding MultiLineColumnWidth, Mode=TwoWay}"
                                        >
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox IsChecked="{Binding Rule.IsMultiLine, Mode=TwoWay}"
                                              VerticalAlignment="Center"
                                    />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                        <GridViewColumn Header="Persisent ?"
                                        Width="{Binding PersistentColumnWidth, Mode=TwoWay}"
                                        >
                            <GridViewColumn.CellTemplate>
                                <DataTemplate>
                                    <CheckBox IsChecked="{Binding Rule.IsPersistent, Mode=TwoWay}"
                                              VerticalAlignment="Center"
                                    />
                                </DataTemplate>
                            </GridViewColumn.CellTemplate>
                        </GridViewColumn>
                    </GridView.Columns>
                </GridView>
            </ListView.View>
        </ListView>
        
        <Grid Grid.Row="1" Grid.Column="1">
            
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>
            
            <Button Content="Edit..."
                    Margin="0,25,0,0"
                    Style="{StaticResource LargeButtonStyle}"
                    Command="{Binding EditCommand, Mode=OneTime}" />
            
            <Button Grid.Row="3" 
                    Content="Delete"
                    Style="{StaticResource LargeButtonStyle}"
                    Command="{Binding DeleteCommand, Mode=OneTime}" />

            <Button Grid.Row="1" 
                    Command="{Binding MoveRuleUpCommand, Mode=OneTime}" 
                    Content="Move up" 
                    Style="{StaticResource LargeButtonStyle}" 
                    VerticalAlignment="Bottom"
                    Margin="0,0,0,6"
                    />

            <Button Grid.Row="2"
                    Margin="0,6,0,0"
                    Command="{Binding MoveRuleDownCommand, Mode=OneTime}" 
                    Content="Move down" 
                    Style="{StaticResource LargeButtonStyle}" 
                    VerticalAlignment="Top"
                    />        
        </Grid>


        <Button Grid.Row="2"
                Content="Add..."
                Margin="5,5,0,5"
                HorizontalAlignment="Left"
                Style="{StaticResource LargeButtonStyle}"
                Command="{Binding AddCommand}" />

        <!-- 3: Default colors -->
        <WrapPanel Grid.Column="0" Grid.Row="3" Grid.ColumnSpan="2"
                   Orientation="Horizontal"
        >
            <!-- foreground / background colors -->
            <StackPanel Margin="5">
                
                <StackPanel Orientation="Horizontal">
                    <TextBlock VerticalAlignment="Center">
                        Default foreground color:
                    </TextBlock>
                    <DropDownCustomColorPicker:CustomColorPicker 
                        SelectedColor="{Binding DefaultForegroundColor, Mode=TwoWay}"
                        Width="40"
                        Margin="5,0,10,0"
                        />

                    <TextBlock VerticalAlignment="Center">
                        Default background color:
                    </TextBlock>
            
                    <DropDownCustomColorPicker:CustomColorPicker 
                        SelectedColor="{Binding DefaultBackgroundColor, Mode=TwoWay}"
                        Width="40"
                        Margin="5,0,10,0"
                        />
                </StackPanel>

                <!-- Sample -->
                <StackPanel Orientation="Horizontal">
                    
                    <TextBlock >Sample text:</TextBlock>
                    <TextBlock Margin="10,0,0,0">
                        <TextBlock.Foreground>
                            <SolidColorBrush Color="{Binding DefaultForegroundColor}" />
                        </TextBlock.Foreground>
                        <TextBlock.Background>
                            <SolidColorBrush Color="{Binding DefaultBackgroundColor}" />
                        </TextBlock.Background>
                        The brown fox jumps over the crazy dog, but my tailor is rich.
                    </TextBlock>
                </StackPanel>
            </StackPanel>

            <!-- highlight colors -->
            <StackPanel Margin="5">
                
                <StackPanel Orientation="Horizontal">

                    <TextBlock VerticalAlignment="Center">
                        Highlight foreground color:
                    </TextBlock>
                    <DropDownCustomColorPicker:CustomColorPicker 
                        SelectedColor="{Binding HighlightForegroundColor, Mode=TwoWay}"
                        Width="40"
                        Margin="5,0,10,0" Height="22" VerticalAlignment="Top"
                        />

                    <TextBlock VerticalAlignment="Center">
                        Highlight background color:
                    </TextBlock>
            
                    <DropDownCustomColorPicker:CustomColorPicker 
                        SelectedColor="{Binding HighlightBackgroundColor, Mode=TwoWay}"
                        Width="40"
                        Margin="5,0,10,0"
                        />
                </StackPanel>

                <!-- Sample -->
                <StackPanel Orientation="Horizontal">
                    <TextBlock >Sample text:</TextBlock>
                    <TextBlock Margin="10,0,0,0">
                        <TextBlock.Foreground>
                            <SolidColorBrush Color="{Binding HighlightForegroundColor}" />
                        </TextBlock.Foreground>
                        <TextBlock.Background>
                            <SolidColorBrush Color="{Binding HighlightBackgroundColor}" />
                        </TextBlock.Background>
                        The brown fox jumps over the crazy dog, but my tailor is rich.
                    </TextBlock>
                </StackPanel>
            </StackPanel>
            
        </WrapPanel>
            <!-- 4: sample text -->
            <StackPanel Orientation="Horizontal"
                        Grid.Row="4" Grid.ColumnSpan="2"
                        Margin="5,10,0,0"
                        >
            
            </StackPanel>

        <!-- 5: OK/Cancel-->
        <StackPanel Orientation="Horizontal"
                    Grid.Row="5" Grid.ColumnSpan="2"
                    Margin="0,10,0,0"
                    HorizontalAlignment="Right">
            <Button Content="OK"
                    Style="{StaticResource LargeButtonStyle}"
                    IsDefault="True"
                    Command="{Binding OKCommand}" />
            <Button Content="Cancel"
                    Style="{StaticResource LargeButtonStyle}"
                    Margin="20,0,0,0"
                    IsCancel="True"
                    Command="{Binding CancelCommand}" />
            
        </StackPanel>
    </Grid>
</Window>
